<template>
<div>
    <HomeHeader></HomeHeader>
    <HomeSwiper :swiperList='swiperList'></HomeSwiper>
    <HomeIcons :iconsList='iconsList'></HomeIcons>
    <Recomment :recommendList='recommendList'></Recomment>
    <Weekend :weekendList='weekendList'></Weekend>
    <HomeFooter></HomeFooter>
</div>
</template>

<script>

import axios from 'axios'
import HomeHeader from './components/Header'
import HomeSwiper from './components/swiper'
import HomeIcons from './components/icons'
import Recomment from './components/Recomment'
import Weekend from './components/Weekend'
import HomeFooter from './components/HomeFooter'
import {mapState} from 'vuex'

export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    Recomment,
    Weekend,
    HomeFooter
  },
  mounted () {
    this.lastCity = this.city
    this.getHomeinfo()
  },
  computed: {
    ...mapState(['city'])
  },
  data () {
    return {
      iconsList: [],
      recommendList: [],
      swiperList: [],
      weekendList: [],
      lastCity: ''
    }
  },
  activated () {
    if (this.lastCity !== this.city) {
      this.getHomeinfo()
      this.lastCity = this.city
    }
  },
  methods: {
    getHomeinfo () {
      axios.get('/api/index.json?city=' + this.city)
        .then(this.getHomeinfocc)
    },
    getHomeinfocc (res) {
      res = res.data
      if (res.ret && res.data) {
        this.iconsList = res.data.iconsList
        this.recommendList = res.data.recommendList
        this.swiperList = res.data.swiperList
        this.weekendList = res.data.weekendList
      }
    }
  }
}
</script>

<style>

</style>


